package com.douyuehan.doubao;

import com.douyuehan.doubao.jwt.JwtAuthenticationFilter;
import com.douyuehan.doubao.rabbitmq.send.SendService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
//mapper接口有@Repository则此处无需再次扫描
//@MapperScan("com.douyuehan.doubao.project.mapper")
@SpringBootApplication
public class DoubaoApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DoubaoApplication.class);
    }
    @Bean
    public FilterRegistrationBean jwtFilter() {
        //springboot自己提供的注册bean
        final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        //把我们的过滤器注册到框架里,然后每个请求都会先进过滤器在进controller
        registrationBean.setFilter(new JwtAuthenticationFilter());
        return registrationBean;
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(DoubaoApplication.class, args);
        SendService sendService = (SendService) run.getBean("sendService");
        sendService.sendDirectMessage("");
        sendService.sendFanoutMessage("");
        sendService.sendTopicMessage("aa.bb");
        run.getBean("receiveService");
    }
}
